package tests_dao;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import dao.CrudService;
import dao.CrudServiceImpl;
import entities.Currency;
import entities.ExchangeRate;

public class TopExchangeRateTest
{
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
	
	@Test
	public void topExchangeRateTest() throws ParseException
	{
		List<String> result = new CrudServiceImpl().topExchangeRate(sdf.parse("1-10-2014"), sdf.parse("4-12-2014"));

		Assert.assertEquals("def", result.get(0));
	}

	@BeforeClass
	public void beforeClass() throws ParseException
	{
		CrudService crud_service = new CrudServiceImpl();
		
		crud_service.clearDataBase();

		Currency abc = new Currency("abc", "abc currency");
		Currency def = new Currency("def", "def currency");
		Currency ghi = new Currency("ghi", "ghi currency");

		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");

		ExchangeRate ex1 = new ExchangeRate(sdf.parse("1-11-2014"), abc, 1, new BigDecimal(6));
		ExchangeRate ex2 = new ExchangeRate(sdf.parse("1-12-2014"), abc, 1, new BigDecimal(3));
		ExchangeRate ex3 = new ExchangeRate(sdf.parse("1-11-2014"), def, 1, new BigDecimal(8));
		ExchangeRate ex4 = new ExchangeRate(sdf.parse("1-12-2014"), def, 1, new BigDecimal(14));
		ExchangeRate ex5 = new ExchangeRate(sdf.parse("1-11-2014"), ghi, 1, new BigDecimal(3));
		ExchangeRate ex6 = new ExchangeRate(sdf.parse("1-12-2014"), ghi, 1, new BigDecimal(4));
		
		crud_service.addCurrency(abc);
		crud_service.addCurrency(def);
		crud_service.addCurrency(ghi);

		crud_service.addExchangeRate(ex1);
		crud_service.addExchangeRate(ex2);
		crud_service.addExchangeRate(ex3);
		crud_service.addExchangeRate(ex4);
		crud_service.addExchangeRate(ex5);
		crud_service.addExchangeRate(ex6);
	}

	@AfterClass
	public void afterClass()
	{
		new CrudServiceImpl().clearDataBase();
	}

}